from flask import Flask,render_template,request,session,redirect,url_for,flash

app = Flask(__name__)
app.secret_key = 'dsdfssdffsd'

@app.route('/')
def index():
    username = session.get('username')
    if 'username' in session:
        return render_template('index.html',username = username)
    return redirect(url_for('login'))

@app.route('/login',methods=['GET','POST'])
def login():
    if request.method == 'POST':
        if request.form['username'] == 'admin' and request.form['password'] == '123':
            session['username'] = request.form['username']
            session['password'] = request.form['password']
            flash('恭喜您，登录成功！',category='info')
            return redirect(url_for('index'))
        else:
            flash('用户名或密码错误',category='error')
            # return f'输入错了'
    return  render_template('login.html')

if __name__ == '__main__':
    app.run(debug=True)

